package cn.cvs.controller;

import cn.cvs.pojo.SysUser;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.sql.Date;
import java.util.Map;


/**
 * @auth 邝志豪
 * @date 2024/1/18 13:51
 */
@Controller
@RequestMapping("/hello")
public class HelloController {
    Logger logger = Logger.getLogger(HelloController.class);

//    @RequestMapping(value = "/hello")
//    public String hello() throws Exception {
//        logger.info("我的第一个SpringMVC程序，运行成功啦！");
//        return "hello";
//    }

//    @RequestMapping(value = "/hello")
//    public String hello(@RequestParam String realName)throws Exception {
//        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
//        return "hello";
//    }
    @RequestMapping(value = "/hello")
    public String hello(@RequestParam (required = false) String realName)throws Exception {
        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
        return "hello";
    }

    @RequestMapping(value = "/hello2")
    public String hello2(@RequestParam (value = "userName",required = false) String realName)throws Exception {
        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
        return "hello";
    }

//    @RequestMapping(value = "/hello2")
//    public String hello2() throws Exception {
//        logger.info("hello控制器下的另一个接口");
//        return "hello";
//    }
    @RequestMapping(value = "/hello3")
    public ModelAndView hello3(@RequestParam String realName)throws  Exception{
            logger.info("你好【"+realName+"】欢迎来到Spring MVC课堂。");
            ModelAndView modelAndView=new ModelAndView();
            modelAndView.addObject("realName",realName);
            modelAndView.setViewName("hello");
            return  modelAndView;
        }
    @RequestMapping(value = "/hello4")
    public String hello4(Model model,@RequestParam  String realName)throws Exception {
        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
        model.addAttribute("realName",realName);
        return "hello";
    }


    @RequestMapping(value = "/hello5")
    public String hello5(Model model,@RequestParam  String realName)throws Exception {
        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
        model.addAttribute("realName",realName);
        model.addAttribute(realName);
        return "hello";
    }


    @RequestMapping(value = "/hello6")
    public String hello6(Model model,@RequestParam  String realName)throws Exception {
        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
        model.addAttribute("realName",realName);
        model.addAttribute(realName);
        SysUser sysUser=new SysUser();
        sysUser.setRealName(realName);
        model.addAttribute("currentUser",sysUser);
        model.addAttribute(sysUser);
        return "hello";
    }

    @RequestMapping(value = "/hello7")
    public String hello7(Map<String,Object> map, @RequestParam  String realName)throws Exception {
        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
        map.put("realName",realName);
        return "hello";
    }



}


